package com.zlq.login.controller;

import com.zlq.login.dao.UserDaoLo;
import com.zlq.login.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/deleteServlet")
public class DeleteController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        resp.setCharacterEncoding("UTF-8");

        int id = Integer.parseInt(req.getParameter("id"));

        UserDaoLo ud = new UserDaoLo();
        User user = new User();

        user.setId(id);
        int i=ud.delete(user);

        System.out.println(i);
//        resp.sendRedirect("/listByPageController?pagenum=0");

        req.getRequestDispatcher("/listByPageController?pagenum=0").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        req.setCharacterEncoding("UTF-8");
//        resp.setContentType("text/html;charset=UTF-8");
//        resp.setCharacterEncoding("UTF-8");
//
//        int id = Integer.parseInt(req.getParameter("id"));
//
//        UserDaoLo ud = new UserDaoLo();
//        User user = new User();
//
//        user.setId(id);
//        int i=ud.delete(user);
//
//        System.out.println(i);
////        resp.sendRedirect("/static/listUser.jsp");
//
//        req.getRequestDispatcher("/listByPageController").forward(req, resp);
    }
}
